//
//  ZQTextField.m
//  BuDeJie
//
//  Created by 仲琦 on 16/4/7.
//  Copyright © 2016年 仲琦. All rights reserved.
//

#import "ZQTextField.h"

@interface ZQTextField ()



@end
@implementation ZQTextField


- (void)awakeFromNib
{
    
    //设置光标的颜色
    self.tintColor = [UIColor whiteColor];
    
    
    //监听文本框编辑
    [self addTarget:self action:@selector(textBegin) forControlEvents:UIControlEventEditingDidBegin];
    
    //监听文本框结束编辑
    [self addTarget:self action:@selector(textEnd) forControlEvents:UIControlEventEditingDidEnd];
    
//    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
//    dict[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
//    self.attributedPlaceholder = [[NSAttributedString alloc]initWithString:self.placeholder attributes:dict];

    
    UILabel *placeholderLabel = [self valueForKey:@"placeholderLabel"];
    placeholderLabel.textColor = [UIColor lightGrayColor];
    
}


- (void)textBegin
{
    //第一种方法
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[NSForegroundColorAttributeName] = [UIColor whiteColor];
    //让占位文字颜色变成白色
    self.attributedPlaceholder = [[NSAttributedString alloc]initWithString:self.placeholder attributes:dict];
    

    
}

- (void)textEnd
{
    //第二种方法
    UILabel *placeholderLabel = [self valueForKey:@"placeholderLabel"];
    placeholderLabel.textColor = [UIColor lightGrayColor];
}
@end
